﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Jumpton.SFA.Server.Entity;
using Jumpton.Persistent;
using System.Data;

namespace Jumpton.SFA.Server.BusinessRule.MasterData
{
    public class PaymentManager:BusinessLogic
    {
        public ObjectTable GetCourseTable()
        {
            return new ObjectTable(typeof(PAYMENTS_INFO));
        }

        public PAYMENTS_INFO Load(int customerID)
        {
            return (PAYMENTS_INFO)ObjectRow.Load(typeof(PAYMENTS_INFO), string.Format("this.CUSTOMERID={0}", customerID));
        }

        public bool Save(PAYMENTS_INFO payment)
        {
            bool Successful = false;
            if (payment != null)
            {
                try
                {
                   
                    
                    payment.Save();
                    Successful = true;
                }
                catch (Exception err)
                {
                    message = err.Message;throw err;
                    
                }
            }

            return Successful;
        }

        public bool Delete(PAYMENTS_INFO payment)
        {
            bool Successful = false;
            if (payment != null)
            {
                try
                {
                    payment.Delete();
                    Successful = true;
                }
                catch (Exception err)
                {
                    message = err.Message;throw err;
                    
                }
            }

            return Successful;
        }

        /// <summary>
        /// 创建付款方式
        /// </summary>
        /// <param name="sapCode">SAP编号</param>
        /// <param name="description">描述</param>
        /// <param name="type">类型</param>
        /// <param name="percents"></param>
        /// <param name="dueDays">帐期</param>
        /// <param name="valid">是否有效</param>
        /// <param name="domainID">域ID</param>
        /// <param name="createBy">创建人</param>
        /// <param name="peyTermGroupID">付款方式组</param>
        /// <returns></returns>
        public static decimal CreatePayTerm(string sapCode, string description, decimal type, decimal percents, decimal dueDays, bool valid, decimal domainID, string createBy, decimal peyTermGroupID)
        {
            PAY_TERMS payTerms = new PAY_TERMS();
            //payTerms.ID = GetCurrentValue("PAY_TERMS", 0);
            payTerms.SAPCODE = sapCode;
            payTerms.DESCRIPTION = description;
            payTerms.TYPE = (int)type;
            payTerms.PERCENT = percents;
            payTerms.DUEDAYS = dueDays;
            payTerms.ACTIVE = valid;
            payTerms.DOMAINID = domainID;
            payTerms.LAST_UPDATER = createBy;
            payTerms.LAST_UPDATE_TIME = BusinessLogic.GetDateTimeDecimal(DateTime.Now);
            payTerms.PAYTERMGROUPID = peyTermGroupID;

            try
            {
                new PayItemManager().Save(payTerms);
                //payTerms.Save();
                return payTerms.ID;
            }
            catch (Exception err)
            {
                throw new Exception(err.Message);
               
            }
        }

    }
}
